package cn.lg.soar.common.util.jackson.serializer;

import cn.lg.soar.common.util.DatetimeUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.util.Date;

/**
 * LocalTime序列化
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
public class SDateSerializer extends JsonSerializer<Date> {

    private final String pattern;

    public SDateSerializer() {
        this.pattern = DatetimeUtil.PATTERN;
    }

    public SDateSerializer(String pattern) {
        this.pattern = pattern;
    }

    @Override
    public void serialize(Date value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        gen.writeString(DatetimeUtil.format(value, pattern));
    }

}
